package xyz.fuqufyb.aec.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import xyz.fuqufyb.aec.data.JsonResult;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.ApiSystemparam;
import xyz.fuqufyb.aec.service.IApiSystemparamService;

import java.util.Arrays;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: ApiSystemParamController
 * @date 时间: 2021/2/2 17:39
 *
 * 系统参数管理 接口
 */
@RestController
@RequestMapping("/sys/systemparaters")
public class ApiSystemParamController {

    @Autowired
    private IApiSystemparamService apiSystemparamService;

    /**
     * 分页加模糊查询  名称与状态查询
     * @param maps
     * @return
     */
    @RequestMapping("/table")
    public TableResult getTable(@RequestParam Map<String,Object> maps){
        try {
            TableResult pageApiSystemparam = apiSystemparamService.getPageApiSystemparam(maps);
            return pageApiSystemparam;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return TableResult.getTableResultError();
    }

    /**
     * 新增
     * @param apiSystemparam
     * @return
     */
    @PostMapping("/add")
    public JsonResult addApiSystemparam(ApiSystemparam apiSystemparam) {
        int i = apiSystemparamService.insertSelective(apiSystemparam);
        if (i > 0) {
            return JsonResult.getJsonSuccess("新增成功");
        }
        return JsonResult.getJsonError();

    }

    /**
     * 修改
     * @param apiSystemparam
     * @return
     */
    @PostMapping("/update")
    public JsonResult updateApiSystemparam(ApiSystemparam apiSystemparam) {
        int i = apiSystemparamService.updateByPrimaryKeySelective(apiSystemparam);
        if (i > 0) {
            return JsonResult.getJsonSuccess("更新成功");
        }
        return JsonResult.getJsonError();
    }

    /**
     * 删除批量
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public JsonResult delApiSystemparam(@RequestParam("ids") Integer[] ids) {
        int i = apiSystemparamService.deleteBySystemparIds(Arrays.asList(ids));
        if (i > 0) {
            return JsonResult.getJsonSuccess("删除成功");
        }
        return JsonResult.getJsonError();
    }


}
